import fileUtil
import fetchUtil
import dbUtil
import logUtil
import math
import time
import random
import traceback

logger = logUtil.logger
f = fileUtil.fetchRecord()
c = fileUtil.config()
def excuete():
    fetchRecord = f.load()
    if fetchRecord.ak == None:
        logger.info('今日已无可用ak，请明日再试')
        return False
    
    fetchRecord.ak = c.getNextAk(fetchRecord.ak)
    logger.debug('切换下一个ak值:%s' ,fetchRecord.ak)
    fetchRecord.save()
    return True

def run():
    flag = True
    while flag:
        try:
            flag = excuete()
            time.sleep(random.uniform(0,2))
        except BaseException :
            traceback.print_exc()
            logger.exception('出现未知异常！')

if __name__ == '__main__':
    run()
        
